<template>
  <c-view>
    <template v-slot:header>
      <div class="title">
        {{ $route.meta.title }}
      </div>
    </template>
    <div class="main__box">
      <c-table
        ref="cTable"
        selection
        hasBorder
        :max-height="maxHeight"
        :size="size"
        :loading="isLoading"
        :table-header="tableHeader"
        :table-list="tableList"
        :table-inner-btns="tableInnerBtns"
        :page-info="pageInfo"
        @change-pagination="changePagination"
      >
        <template v-slot:header>
          <c-search :form-model="searchObj" :form-items="searchItems" @submit-form="searchSubmit" @reset-form="searchReset"></c-search>
        </template>
      </c-table>
    </div>
  </c-view>
</template>

<script>
import mixinTable from 'mixins/table'
import utils from 'utils'

export default {
  name: 'memberCancel',
  mixins: [mixinTable],
  data(vm) {
    return {
      tableInnerBtns: [
        {
          name: '重置预约订单取消次数',
          icon: 'el-icon-refresh',
          handle(row, index) {
            vm.confirmTip('确定重置', () => {
              vm.doCancel(row.id, index)
            })
          }
        }
      ],
      // 表格内操作按钮
      tableHeader: [
        {
          label: '姓名',
          prop: 'memberName',
          width: 120,
          search: {
            type: 'input'
          }
        },
        {
          label: '手机号码',
          prop: 'phone',
          width: 110,
          formatter: row => row && utils.hidePhoneNum(row.phone),
          isPopover: true,
          search: {
            type: 'input'
          }
        },
        {
          label: '取消约车次数',
          prop: 'orderCancelTime',
          width: 120
        }
      ]
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    /*
     * 查询表格列表数据
     */
    fetchData() {
      const { pageNo, pageSize } = this.pageInfo
      const { dateTime, ...other } = this.searchObj
      const searchDate = this.getSearchDate(dateTime, 'dateTime')
      this.isLoading = true
      this.$api.member
        .fetch('cancelOrderList', {
          ...searchDate,
          ...other,
          rows: pageNo,
          offset: pageSize
        })
        .then(res => {
          this.isLoading = false
          if (res && res.totalCount) {
            const { data, totalCount } = res
            this.pageInfo.totalNum = totalCount
            this.tableList = data || []
          } else {
            this.tableList = res || []
          }
        })
    },
    doCancel(id, index) {
      this.$api.member
        .fetch('resetMemberCancelOrder', {
          id
        })
        .then(() => {
          this.$msgTip('重置成功')
          this.tableList[index].orderCancelTime = 0
        })
    }
  }
}
</script>
